﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TRTCMain.Controls
{
    public partial class UsersButton : UserControl
    {
        public delegate void BtnClickHandler();
        public event BtnClickHandler BtnClicked;
        private int userCount = 0;
        private Font font = new Font("微软雅黑", 8);
        private SolidBrush msgbrush = new SolidBrush(Color.FromArgb(255, 220, 220, 220));

        public UsersButton()
        {
            InitializeComponent();
            this.Click += Label_Click;
            this.label.Click += Label_Click;
            this.pictureBox.Click += Label_Click;
            this.MouseMove += MicroButton_MouseMove; ;
            this.MouseLeave += MicroButton_MouseLeave; ;
            pictureBox.MouseMove += PictureBox_MouseMove; ;
            pictureBox.MouseLeave += PictureBox_MouseLeave; ;
            label.MouseMove += Label_MouseMove; ;
            label.MouseLeave += Label_MouseLeave;
        }

        private void Label_MouseLeave(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(32, 34, 36);
        }

        private void Label_MouseMove(object sender, MouseEventArgs e)
        {
            this.BackColor = Color.FromArgb(69, 70, 72);
        }

        private void PictureBox_MouseLeave(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(32, 34, 36);
        }

        private void PictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            this.BackColor = Color.FromArgb(69, 70, 72);
        }

        private void MicroButton_MouseLeave(object sender, EventArgs e)
        {
            this.BackColor = Color.FromArgb(32, 34, 36);
        }

        private void MicroButton_MouseMove(object sender, MouseEventArgs e)
        {
            this.BackColor = Color.FromArgb(69, 70, 72);
        }

        public void SetUserCount(int count) {
            userCount = count;
            this.Refresh();
        }

        private void Label_Click(object sender, EventArgs e)
        {
            BtnClicked?.Invoke();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            string count = string.Empty;
            if (userCount > 99)
            {
                count = "99+";
            }
            else
            {
                count = userCount.ToString();
            }
            e.Graphics.DrawString(count, font, msgbrush, this.Width - 20, 5);          
        }
    }
}
